<script setup lang="ts">
/*
 * @description:商品表
 * @author: lxx
 * @date: 2025-7-29
 * @version: V1.0.0
 */
import { dataSaveApi } from '@/api/goods'
import type { ItemFormInt } from '@/api/goods/types'
import { useAddEdit } from '@/hooks/system/useFramework'
import constants  from '@/common/constant'
const dataFormRef = ref()
const formData = ref<ItemFormInt>({
  /** ID */
  id: -1,
  /** 商品名称 */
  goodName: '',
  /** 单位 */
  goodUnit: '',
  /** 库存数量 */
  goodNum: 1,
  /** 价格 */
  goodPrice: 0,
  /** 成本价 */
  goodCostPrice: 0,
  /** 商品图片 */
  goodImgs: '',
  /** 商品型号 */
  goodModel: '',
  /** 商品类型（镜架 镜片等） */
  goodType: '',
  /** 规格 */
  goodSpecs: '',
  /** 备注 */
  memo: ''
})
const { isEdit, loading, dialog, open, handleSubmitClick, handleCloseDialog } = useAddEdit<ItemFormInt>(dataSaveApi, formData, dataFormRef)
const rules = {
  /** 商品名称 */
  goodName: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
  /** 单位 */
  goodUnit: [{ required: true, message: '请输入单位', trigger: 'blur' }],
  /** 库存数量 */
  goodNum: [{ required: true, message: '请输入库存数量', trigger: 'blur' }],
  /** 价格 */
  goodPrice: [{ required: true, message: '请输入价格', trigger: 'blur' }],
  /** 成本价 */
  goodCostPrice: [{ required: true, message: '请输入成本价', trigger: 'blur' }],
  /** 商品图片 */
  // goodImgs: [{ required: true, message: '请输入商品图片', trigger: 'blur' }],
  /** 商品型号 */
  goodModel: [{ required: true, message: '请输入商品型号', trigger: 'blur' }],
  /** 商品类型（镜架 镜片等） */
  goodType: [{ required: true, message: '请输入商品类型（镜架 镜片等）', trigger: 'blur' }],
  /** 规格 */
  goodSpecs: [{ required: true, message: '请输入规格', trigger: 'blur' }]
}
defineExpose({
  open
})
</script>
<template>
  <!--字典弹窗-->
  <el-dialog body-class="dialogBody" v-loading="loading" v-model="dialog.visible" :title="dialog.title" width="500px" @close="handleCloseDialog">
    <el-form ref="dataFormRef" :model="formData" :rules="rules" label-width="80px">
      <el-form-item label="商品名称" prop="goodName">
        <el-input v-model="formData.goodName" placeholder="请输入商品名称" />
      </el-form-item>
      <el-form-item label="单位" prop="goodUnit">
        <Dict fill :code="constants.GOODS_UNIT" v-model="formData.goodUnit" type="select" />
      </el-form-item>
      <el-form-item label="库存数量" prop="goodNum">
        <el-input :disabled="isEdit" v-model="formData.goodNum" placeholder="请输入库存数量" />
      </el-form-item>
      <el-form-item label="价格" prop="goodPrice">
        <el-input v-model="formData.goodPrice" placeholder="请输入价格" />
      </el-form-item>
      <el-form-item label="成本价" prop="goodCostPrice">
        <el-input v-model="formData.goodCostPrice" placeholder="请输入成本价" />
      </el-form-item>
      <el-form-item label="商品型号" prop="goodModel">
        <el-input v-model="formData.goodModel" placeholder="请输入商品型号" />
      </el-form-item>
      <el-form-item label="商品类型" prop="goodType">
        <!-- <el-input v-model="formData.goodType" placeholder="请输入商品类型" /> -->
        <Dict :code="constants.GOODS_TYPE" v-model="formData.goodType" type="radio" />
      </el-form-item>
      <el-form-item label="规格" prop="goodSpecs">
        <el-input v-model="formData.goodSpecs" placeholder="请输入规格" />
      </el-form-item>
      <!-- <el-form-item label="商品图片" prop="goodImgs">
        <el-input v-model="formData.goodImgs" placeholder="请输入商品图片" />
      </el-form-item> -->
      <el-form-item label="备注" prop="memo">
        <el-input v-model="formData.memo" placeholder="请输入备注" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="handleSubmitClick()">确 定</el-button>
        <el-button @click="handleCloseDialog()">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<style lang="scss" scoped></style>
